﻿using System;
using System.Collections.Generic;
using System.Xml.Linq;
using data.contracts.messages;
using ebcpatterns.flow;
using fileadapter;
using generator;
using modelbuilder;
using modelbuilder.parts;
using projectfile;

namespace ebc.compiler
{
    internal class Program
    {
        private static int Main(string[] args) {
            Console.WriteLine("EBC Compiler - 2010 - Stefan Lieser & Ralf Westphal");
            if (args.Length != 1) {
                Console.WriteLine("Syntax: ebc.compiler <project filename>");
                return 1;
            }

            var mainboard = new Mainboard(
                new GetEbcXmlFilenames(new ProjectReader(), new ProjectParser()),
                new DefaultNamespace(new ProjectReader(), new ParseDefaultNamespace()),
                new ModelBuilder(
                    new XmlFileAdapter(),
                    new Join<IEnumerable<XDocument>, string, Tuple<IEnumerable<XDocument>, string>>(),
                    new BoardBuilder(),
                    new ExpandSplitWires(),
                    new ExpandJoinWires(),
                    new Parse_Pins()),
                new GetGeneratedEbcCsFilename(new ProjectReader(), new ProjectParser()),
                new Generator(),
                new Join<string, string, SaveMessage>(),
                new FileAdapter());

            try {
                mainboard.Run(args[0]);
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
                return 1;
            }
            return 0;
        }
    }
}